<template>
	<view class="container">
		<u-navbar title=" " leftIcon=" " :autoBack="false" bgColor="transparent" :placeholder="true"></u-navbar>
		<image :src='welcom_icon1' class="bg1"></image>
		<image :src='welcom_icon2' class="bg2"></image>
		<image :src='welcom_logo' class="logo"></image>
		<view class="skip" @click="jump">
			跳过
			<text>{{count}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				timer: null,
				count: 10, // 倒计时初始值
				welcom_icon1: this.$Config.HTTP_REQUEST_URL + "/img/welcom-icon1.png",
				welcom_icon2: this.$Config.HTTP_REQUEST_URL + "/img/welcom-icon2.png",
				welcom_logo: this.$Config.HTTP_REQUEST_URL + "/img/welcom-logo.png",
			};
		},
		onLoad() {
			// 启动倒计时

			if (uni.getStorageSync('isFirstIn')) {
				this.jump()
			} else {
				this.startTimer();
				uni.setStorageSync('isFirstIn', true)
			}
		},
		destroyed() {
			// 页面卸载时清除定时器
			if (this.timer) {
				clearInterval(this.timer);
				this.timer = null
			}
		},
		onUnload() {
			// 页面卸载时清除定时器
			if (this.timer) {
				clearInterval(this.timer);
				this.timer = null
			}
		},
		methods: {
			startTimer() {
				this.timer = setInterval(() => {
					if (this.count > 0) {
						this.count--;
					} else {
						this.jump();
					}
				}, 1000);
			},
			jump() {
				// 清除定时器
				if (this.timer) {
					clearInterval(this.timer);
					this.timer = null;
				}
				// 跳转到mine页面
				uni.switchTab({
					url: "/pages/index/index",
				});
			},
		},
	};
</script>

<style lang="less" scoped>
	.container {
		min-height: 100vh;
		background: #edf8fe;
		position: relative;
	}

	.bg1 {
		width: 304.81rpx;
		height: 537.43rpx;
		position: absolute;
		right: 0;
		top: 0;
		z-index: 99;
	}

	.bg2 {
		width: 417.11rpx;
		height: 501.34rpx;
		position: absolute;
		left: 0;
		bottom: 0;
		z-index: 99;
	}

	.logo {
		width: 150.4rpx;
		height: 192.51rpx;
		position: absolute;
		left: 50%;
		top: 50%;
		margin-left: -75.2rpx;
		margin-top: -96.255rpx;
		z-index: 99;
	}

	.skip {
		width: 126rpx;
		height: 50rpx;
		line-height: 50rpx;
		text-align: center;
		background: rgba(0, 149, 248, 0.08);
		border-radius: 26rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #0095f8;
		font-style: normal;
		margin-left: 30rpx;

		text {
			margin-left: 8rpx;
		}
	}
</style>